﻿Imports System.Data.OleDb

Public Class profile
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Check if the user is viewing their own profile page
        If Request.Params("userUName") = User.Identity.Name Then

            'If yes, show the edit profile button
            btn_editProfile.Visible = True
        Else

            'If no, hide the edit profile button
            btn_editProfile.Visible = False

        End If
      
    End Sub
    'Function for turning the stars into asterisks or images
    ' Declare the function to get at stars as a number
    Protected Function getAge(ByVal age As Integer)

        'Declare the variable that will be returned
        Dim retval As String

        'Tell it that retval is equal to nothing
        retval = ""

        Select Case age
            Case Is < 20
                Return retval + "<img src='img/upto19.png'/>"
            Case Is < 30
                Return retval + "<img src='img/upto29.png'/>"
            Case Is < 40
                Return retval + "<img src='img/upto39.png'/>"
            Case Is < 50
                Return retval + "<img src='img/upto49.png'/>"
            Case Is < 60
                Return retval + "<img src='img/upto59.png'/>"
            Case Is > 59
                Return retval + "<img src='img/60plus.png'/>"
        End Select

        'Then return the varaible
        Return retval

    End Function

    'Function for turning the stars into asterisks or images
    ' Declare the function to get at stars as a number
    Protected Function getStars(ByVal stars As Integer)

        'Declare the variable that will be returned
        Dim retval As String

        'Tell it that retval is equal to nothing
        retval = ""

        'Loop for each number of stars 
        For i = 1 To stars
            'and for each one add an asterisk
            retval = retval + "<img src='img/cupcake.png' />"
        Next

        'Then return the varaible
        Return retval

    End Function

    'Function for turning the stars into asterisks or images
    ' Declare the function to get at stars as a number
    Protected Function getUserStars(ByVal userStar As Integer)

        'Declare the variable that will be returned
        Dim retval As String

        'Tell it that retval is equal to nothing
        retval = ""

        'Loop for each number of stars 
        For i = 1 To userStar
            'and for each one add an asterisk
            retval = retval + "<img src='img/star2.png' />"
        Next

        'Then return the varaible
        Return retval

    End Function

    Protected Function getDifficulty(ByVal difficulty As Integer)

        'Declare the variable that will be returned
        Dim retval As String

        'Tell it that retval is equal to nothing
        retval = ""

        'Loop for each number of difficulty 
        For i = 1 To difficulty
            'and for each one add an asterisk
            retval = retval + "<img src='img/difficulty.png' />"
        Next

        'Then return the varaible
        Return retval


    End Function

    Protected Sub btn_rate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_rate.Click

        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("diycakeConnectionString").ConnectionString)
        oleDbConn.Open()
        Dim addBakersStarSql As String = "INSERT INTO cakersRating (author, rating, caker_fkid) VALUES (@f1, @f2,@f3)"
        Dim addBakersStarCmd As OleDbCommand = New OleDbCommand(addBakersStarSql, oleDbConn)
        addBakersStarCmd.Parameters.AddWithValue("@f1", User.Identity.Name)
        addBakersStarCmd.Parameters.AddWithValue("@f2", Rating1.CurrentRating)
        addBakersStarCmd.Parameters.AddWithValue("@f3", Request.Params("ID"))
        addBakersStarCmd.ExecuteNonQuery()
        'Close the command objects to help the next page update
        addBakersStarCmd.Dispose()
        oleDbConn.Close()
        oleDbConn.Dispose()
        'Redirect the user to the page with the updated rating
        Response.Redirect("profile.aspx?ID=" & Request.Params("ID"))
    End Sub

    Protected Sub btn_editProfile_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_editProfile.Click

        Response.Redirect("editProfile.aspx?userUName=" & Request.Params("userUName"))
    End Sub
End Class